<!-- 订单评价-->
<template>
	<view class="no-warpper">
		<view class="nl-shadow-box">
			<view class="nl-flex-list">
				<text>服务评分</text>
				<view class="right">
					<u-rate :count="count" active-color="#FFC02D" v-model="formData.appraiseScore"></u-rate>
				</view>
			</view>

			<!-- 服务评价 -->
			<view class="nl-flex-title">服务评价</view>
			<view class="textarea-padding">
				<u-input v-model="formData.context" placeholder-style="color: #AFAFAF;font-size: 28rpx;" type="textarea" border
					placeholder="请填写本地服务评价" />
			</view>

			<view class="button-lg" @click="submit()">
				<!-- 提交 -->
				<button>提交</button>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import {
		appraiseRepair
	} from 'api/repair';
	export default {
		data() {
			return {
				count: 5,
				formData: {
					appraiseScore: '', //评价等级
					context: '', //评价内容
					objId: '', //维修id
					appraiseType: '1001',
					appraiseUserId: '', //用户id
					appraiseUserName: '', //用户名称
					objType: '1001'
				}

			};
		},
		computed: {
			...mapState('user', ['userInfo', 'userCommunity'])
		},
		onLoad(options) {
			console.log('options', options)
			this.formData.objId = options.repairId
			this.formData.appraiseUserId = this.userInfo.userId;
			this.formData.appraiseUserName = this.userInfo.userName;
		},
		methods: {
			/**
			 * 提交
			 */
			submit() {
				var that = this
				if(!this.checkData()){
					return;
				}
				
				appraiseRepair(this.formData).then((res) => {
					console.log('评价成功', res)
					if (res.code == 0 && res.msg == '成功') {
							uni.showToast({
								title: '评价成功',
								icon: 'none',
								duration: 1500
							})
							setTimeout(() => {
								uni.navigateBack()
							}, 1500)
					}
				})

			},
			/**
			 * 表单校验
			 */
			checkData() {
				return this.$checkFrom({
					formData: this.formData
				}, {
					'formData.appraiseScore': [{
						limit: "required",
						param: "",
						errInfo: "请选择服务评分"
					}],
					'formData.context': [{
						limit: "required",
						param: "",
						errInfo: "请输入服务评价"
					}]
				});
			},
		}
	}
</script>

<style lang="scss">
	.nl-flex-title {
		border-bottom: none
	}

	.textarea-padding {
		padding: 0 24rpx 24rpx;
		border-bottom: 2rpx solid $uni-bg-color-grey;
	}
</style>
